package eval.host.compare;

import java.util.Collections;
import java.util.List;
import com.google.inject.Singleton;
import eval.host.Host;

/**
 * This class is used  to sort the hosts in the cloud,
 * according to the age oldest VM at hosts
 * 
 * @author Amit Peled   <amit.kapina@gmail.com>
 * @author Igal Kaufman <igal.kaufman@gmail.com> 
 */
@Singleton
public class AgeHostSortList implements ISortHostList{

	/* (non-Javadoc)
	 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
	 */
	@Override
	public int compare(Host host1, Host host2) {
		return 	 host2.findTheOldestVmInHost() - host1.findTheOldestVmInHost();
	}

	/* (non-Javadoc)
	 * @see eval.host.compare.ISortHostList#sortHostList(java.util.List)
	 */
	@Override
	public List<Host> sortHostList(List<Host> hostToSort) {
		Collections.sort(hostToSort,this);
		return hostToSort;
	}

}
